package org.linlinjava.litemall.admin.controller;

import java.util.List;

import javax.validation.constraints.NotNull;

import org.linlinjava.litemall.admin.beans.annotation.LogAnno;
import org.linlinjava.litemall.admin.dto.LitemallTaxDTO;
import org.linlinjava.litemall.admin.service.AdminTaxService;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort;
import org.linlinjava.litemall.db.domain.LitemallTax;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 税收管理控制器
 *
 * @author yliyun
 * @description：TODO
 * @date 2022/09/14
 */
@RestController
@RequestMapping("/admin/tax")
public class AdminTaxController {
    /**
     * 管理税务服务
     */
    @Autowired
    private AdminTaxService adminTaxService;

    /**
     * 创建
     *
     * @param tax 税
     * @return {@link Object}
     */
    @PostMapping("/create")
    @LogAnno
    public Object create(@RequestBody LitemallTax tax){
        return adminTaxService.create(tax);
    }

    /**
     * 删除
     *
     * @param id id
     * @return {@link Object}
     */
    @DeleteMapping("/delete")
    @LogAnno
    public Object delete(@NotNull Integer id){
        return adminTaxService.delete(id);
    }

    /**
     * 更新
     *
     * @param tax 税
     * @return {@link Object}
     */
    @PutMapping("/update")
    @LogAnno
    public Object update(@RequestBody LitemallTaxDTO tax){
        return adminTaxService.update(tax);
    }

    /**
     * 查询选择性
     *
     * @param regionId 区域id
     * @param code     代码
     * @param page     页面
     * @param limit    限制
     * @param sort     排序
     * @param order    订单
     * @return {@link Object}
     */
    @GetMapping("/list")
    @LogAnno
    public Object querySelective(Integer regionId,
                                 String code,
                                 @RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer limit,
                                 @Sort @RequestParam(defaultValue = "add_time") String sort,
                                 @Order @RequestParam(defaultValue = "desc") String order){
        return adminTaxService.querySelective(regionId, code, page, limit, sort, order);
    }

    /**
     * 启用
     *
     * @param tax 税
     * @return {@link Object}
     */
    @PutMapping("/enable")
    @LogAnno
    public Object enable(@RequestBody LitemallTax tax){
        return adminTaxService.enable(tax);
    }

    /**
     * 按地区找到id
     *
     * @param firstRegionId  第一个区域id
     * @param secondRegionId 第二个区域id
     * @param regionId       区域id
     * @return {@link Object}
     */
    @GetMapping("/find_by_regionId")
    @LogAnno
    public Object findByRegionId(@RequestParam Integer firstRegionId,
    		@RequestParam Integer secondRegionId,@RequestParam Integer regionId){
    	List<LitemallTax> result = adminTaxService.findByRegionId(firstRegionId, secondRegionId, regionId);
        return ResponseUtil.okList(result);
    }
}
